

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="Blue~u~u~u">
  <meta name="author" content="Blue~u~u~u">
  <meta name="keywords" content="">
  <meta name="description" content="springmvc-day02第一章 RESTFul风格交互方式第一节 RESTFul概述1. REST的概念REST：Representational State Transfer，表现层资源状态转移。   定位：互联网软件架构风格 倡导者：Roy Thomas Fielding 文献：Roy Thomas Fielding的博士论文  2. REST要解决的问题: 将针对功能设计系统转变成针对">
<meta property="og:type" content="article">
<meta property="og:title" content="springmvc-day02">
<meta property="og:url" content="http://www.slx.blue/2021/12/11/springMVC-02/index.html">
<meta property="og:site_name" content="Blue~u~u~u~u">
<meta property="og:description" content="springmvc-day02第一章 RESTFul风格交互方式第一节 RESTFul概述1. REST的概念REST：Representational State Transfer，表现层资源状态转移。   定位：互联网软件架构风格 倡导者：Roy Thomas Fielding 文献：Roy Thomas Fielding的博士论文  2. REST要解决的问题: 将针对功能设计系统转变成针对">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_001.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_002.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_003.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_004.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_005.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_006.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_007.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_008.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_009.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_010.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_011.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_012.png">
<meta property="og:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_014.png">
<meta property="article:published_time" content="2021-12-11T14:24:07.000Z">
<meta property="article:modified_time" content="2021-12-11T14:25:05.247Z">
<meta property="article:author" content="Blue~u~u~u">
<meta property="article:tag" content="springMVC">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://www.slx.blue/2021/12/11/springMVC-02/tu_001.png">
  
  <title>springmvc-day02 - Blue~u~u~u~u</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"www.slx.blue","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":180,"cursorChar":"_","loop":true},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>

<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
<script src="/live2d-widget/autoload.js"></script>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Blue~u~u</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/images/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="springmvc-day02">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-12-11 22:24" pubdate>
        2021年12月11日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      16k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      50 分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">springmvc-day02</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：6 个月前
                
              </p>
            
            <div class="markdown-body">
              <h1 id="springmvc-day02"><a href="#springmvc-day02" class="headerlink" title="springmvc-day02"></a>springmvc-day02</h1><h2 id="第一章-RESTFul风格交互方式"><a href="#第一章-RESTFul风格交互方式" class="headerlink" title="第一章 RESTFul风格交互方式"></a>第一章 RESTFul风格交互方式</h2><h3 id="第一节-RESTFul概述"><a href="#第一节-RESTFul概述" class="headerlink" title="第一节 RESTFul概述"></a>第一节 RESTFul概述</h3><h4 id="1-REST的概念"><a href="#1-REST的概念" class="headerlink" title="1. REST的概念"></a>1. REST的概念</h4><p>REST：<strong>Re</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer，表现层资源状态转移。 </p>
<ul>
<li>定位：互联网软件架构风格</li>
<li>倡导者：Roy Thomas Fielding</li>
<li>文献：Roy Thomas Fielding的博士论文</li>
</ul>
<h4 id="2-REST要解决的问题-将针对功能设计系统转变成针对资源设计系统"><a href="#2-REST要解决的问题-将针对功能设计系统转变成针对资源设计系统" class="headerlink" title="2. REST要解决的问题: 将针对功能设计系统转变成针对资源设计系统"></a>2. REST要解决的问题: 将针对功能设计系统转变成针对资源设计系统</h4><p>传统的软件系统仅在本地工作，但随着项目规模的扩大和复杂化，不但整个项目会拓展为分布式架构，很多功能也会通过网络访问第三方接口来实现。在通过网络访问一个功能的情况下，我们不能轻易假设网络状况稳定可靠。所以当一个请求发出后没有接收到对方的回应，那我们该如何判定本次操作成功与否？</p>
<p>下面以保存操作为例来说明一下针对功能和针对资源进行操作的区别：</p>
<ul>
<li><p>针对功能设计系统</p>
<p>保存一个 Employee 对象，没有接收到返回结果，判定操作失败，再保存一次。但是其实在服务器端保存操作已经成功了，只是返回结果在网络传输过程中丢失了。而第二次的补救行为则保存了重复、冗余但 id 不同的数据，这对整个系统数据来说是一种破坏。</p>
</li>
<li><p>针对资源设计系统</p>
<p>针对 id 为 3278 的资源执行操作，服务器端会判断指定 id 的资源是否存在。如果不存在，则执行保存操作新建数据；如果存在，则执行更新操作。所以这个操作不论执行几次，对系统的影响都是一样的。在网络状态不可靠的情况下可以多次重试，不会破坏系统数据。</p>
</li>
</ul>
<blockquote>
<p>幂等性：如果一个操作执行一次和执行 N 次对系统的影响相同，那么我们就说这个操作满足幂等性。而幂等性正是 REST 规范所倡导的。</p>
</blockquote>
<h4 id="3-RESTFul风格的架构特点"><a href="#3-RESTFul风格的架构特点" class="headerlink" title="3. RESTFul风格的架构特点"></a>3. RESTFul风格的架构特点</h4><h5 id="3-1-通过URL就知道要操作什么资源"><a href="#3-1-通过URL就知道要操作什么资源" class="headerlink" title="3.1 通过URL就知道要操作什么资源"></a>3.1 通过URL就知道要操作什么资源</h5><p>REST是针对资源设计系统，所以在REST中一个URL就对应一个资源， 为实现操作<strong>幂等性</strong>奠定基础。 </p>
<h5 id="3-2-通过Http请求的方式就知道要对资源进行何种操作"><a href="#3-2-通过Http请求的方式就知道要对资源进行何种操作" class="headerlink" title="3.2 通过Http请求的方式就知道要对资源进行何种操作"></a>3.2 通过Http请求的方式就知道要对资源进行何种操作</h5><p>在REST中，针对同一资源的增删改查操作的URL是完全相同的，它是通过Http协议的不同请求方式来区分不同操作的</p>
<p>REST 风格<strong>主张</strong>在项目设计、开发过程中，具体的操作符合 HTTP 协议定义的请求方式的<strong>语义</strong>。</p>
<table>
<thead>
<tr>
<th>操作</th>
<th>请求方式</th>
</tr>
</thead>
<tbody><tr>
<td>查询操作</td>
<td>GET</td>
</tr>
<tr>
<td>保存操作</td>
<td>POST</td>
</tr>
<tr>
<td>删除操作</td>
<td>DELETE</td>
</tr>
<tr>
<td>更新操作</td>
<td>PUT</td>
</tr>
</tbody></table>
<blockquote>
<p>另有一种说法：</p>
<ul>
<li>POST 操作针对功能执行，没有锁定资源 id，是非幂等性操作。</li>
<li>PUT 操作锁定资源 id，即使操作失败仍然可以针对原 id 重新执行，对整个系统来说满足幂等性。<ul>
<li>id 对应的资源不存在：执行保存操作</li>
<li>id 对应的资源存在：执行更新操作</li>
</ul>
</li>
</ul>
</blockquote>
<h5 id="3-3-URL更加简洁也更加隐晦"><a href="#3-3-URL更加简洁也更加隐晦" class="headerlink" title="3.3 URL更加简洁也更加隐晦"></a>3.3 URL更加简洁也更加隐晦</h5><p>REST风格提倡 URL 地址使用统一的风格设计，从前到后各个单词使用斜杠分开，不使用问号键值对方式携带请求参数，而是将要发送给服务器的数据作为 URL 地址的一部分，以保证整体风格的一致性。还有一点是不要使用请求扩展名。</p>
<p>使用问号键值对的方式给服务器传递数据太明显，容易被人利用来对系统进行破坏。使用 REST 风格携带数据不再需要明显的暴露数据的名称。 </p>
<table>
<thead>
<tr>
<th>操作</th>
<th>传统风格</th>
<th>REST 风格</th>
</tr>
</thead>
<tbody><tr>
<td>保存</td>
<td>/CRUD/saveEmp</td>
<td>URL 地址：/CRUD/emp 请求方式：POST</td>
</tr>
<tr>
<td>删除</td>
<td>/CRUD/removeEmp?empId=2</td>
<td>URL 地址：/CRUD/emp/2 请求方式：DELETE</td>
</tr>
<tr>
<td>更新</td>
<td>/CRUD/updateEmp</td>
<td>URL 地址：/CRUD/emp 请求方式：PUT</td>
</tr>
<tr>
<td>查询（表单回显）</td>
<td>/CRUD/editEmp?empId=2</td>
<td>URL 地址：/CRUD/emp/2 请求方式：GET</td>
</tr>
</tbody></table>
<h3 id="第二节-四种请求方式的映射"><a href="#第二节-四种请求方式的映射" class="headerlink" title="第二节 四种请求方式的映射"></a>第二节 四种请求方式的映射</h3><h4 id="1-为什么要进行请求方式的映射"><a href="#1-为什么要进行请求方式的映射" class="headerlink" title="1. 为什么要进行请求方式的映射"></a>1. 为什么要进行请求方式的映射</h4><p>在 HTML 中，GET 和 POST 请求可以天然实现，但是 DELETE 和 PUT 请求无法直接做到。SpringMVC 提供了 <strong>HiddenHttpMethodFilter</strong> 帮助我们<strong>将 POST 请求转换为 DELETE 或 PUT 请求</strong>。</p>
<h4 id="2-具体执行映射操作"><a href="#2-具体执行映射操作" class="headerlink" title="2. 具体执行映射操作"></a>2. 具体执行映射操作</h4><h5 id="2-1-映射PUT-请求"><a href="#2-1-映射PUT-请求" class="headerlink" title="2.1 映射PUT 请求"></a>2.1 映射PUT 请求</h5><h6 id="2-1-1-修改web-xml文件"><a href="#2-1-1-修改web-xml文件" class="headerlink" title="2.1.1 修改web.xml文件"></a>2.1.1 修改web.xml文件</h6><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!--一定要配置在解决乱码的Filter之后--&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">filter</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>hiddenHttpMethodFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">filter-class</span>&gt;</span>org.springframework.web.filter.HiddenHttpMethodFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-class</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">filter-mapping</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>hiddenHttpMethodFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">filter-mapping</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="2-1-2-页面的表单"><a href="#2-1-2-页面的表单" class="headerlink" title="2.1.2 页面的表单"></a>2.1.2 页面的表单</h6><ul>
<li>要点1：原请求方式必须是 post</li>
<li>要点2：新的请求方式名称通过请求参数发送</li>
<li>要点3：请求参数名称必须是 _method</li>
<li>要点4：请求参数的值就是要改成的请求方式</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">th:action</span>=<span class="hljs-string">&quot;@&#123;/rest/movie&#125;&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;_method&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;put&quot;</span>/&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>发送请求<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="2-1-3-handler方法"><a href="#2-1-3-handler方法" class="headerlink" title="2.1.3 handler方法"></a>2.1.3 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PutMapping(&quot;/movie&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">updateMovie</span><span class="hljs-params">()</span></span>&#123;<br>    logger.debug(<span class="hljs-string">&quot;PUT请求....&quot;</span>);<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;target&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="2-2-映射DELETE请求"><a href="#2-2-映射DELETE请求" class="headerlink" title="2.2 映射DELETE请求"></a>2.2 映射DELETE请求</h5><h6 id="2-2-1-web-xml中要维持之前映射PUT请求的配置"><a href="#2-2-1-web-xml中要维持之前映射PUT请求的配置" class="headerlink" title="2.2.1 web.xml中要维持之前映射PUT请求的配置"></a>2.2.1 web.xml中要维持之前映射PUT请求的配置</h6><h6 id="2-2-2-前端页面"><a href="#2-2-2-前端页面" class="headerlink" title="2.2.2 前端页面"></a>2.2.2 前端页面</h6><p>通常删除超链接会出现在列表页面： </p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>将XXX请求转换为DELETE请求<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;app&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;dataTable&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>姓名<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>年龄<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>张三<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>40<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/rest/movie&#125;&quot;</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;deleteMovie&quot;</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>李四<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>30<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/rest/movie&#125;&quot;</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;deleteMovie&quot;</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>创建负责转换的表单</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;myForm&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;_method&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;delete&quot;</span>/&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>使用vue给删除超链接绑定单击响应函数:</p>
<ol>
<li>引入vue</li>
</ol>
<p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_001.png" srcset="/img/loading.gif" lazyload></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-comment">&lt;!--引入vue--&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/static/javaScript/vue.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ol start="2">
<li>绑定单击响应函数</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">var</span> vue = <span class="hljs-keyword">new</span> Vue(&#123;<br>    <span class="hljs-string">&quot;el&quot;</span>:<span class="hljs-string">&quot;#app&quot;</span>,<br>    <span class="hljs-string">&quot;methods&quot;</span>:&#123;<br>        <span class="hljs-function"><span class="hljs-title">deleteMovie</span>(<span class="hljs-params"></span>)</span>&#123;<br>            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;aaaaaaa&quot;</span>)<br>            <span class="hljs-comment">//真正发送删除请求:</span><br>            <span class="hljs-comment">//1. 阻止标签的默认行为</span><br>            event.preventDefault()<br>            <span class="hljs-comment">//2. 创建一个空表单:先动态设置表单的action</span><br>            <span class="hljs-keyword">var</span> myForm = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&quot;myForm&quot;</span>);<br>            myForm.action = event.target.href<br>            <span class="hljs-comment">//并且使用js代码提交表单</span><br>            myForm.submit()<br>        &#125;<br>    &#125;<br>&#125;);<br></code></pre></td></tr></table></figure>

<h6 id="2-2-3-handler方法"><a href="#2-2-3-handler方法" class="headerlink" title="2.2.3 handler方法"></a>2.2.3 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@DeleteMapping(&quot;/movie&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">deleteMovieById</span><span class="hljs-params">()</span></span>&#123;<br>    logger.debug(<span class="hljs-string">&quot;DELETE请求....&quot;</span>);<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;target&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="第三节-PathVariable注解获取路径参数"><a href="#第三节-PathVariable注解获取路径参数" class="headerlink" title="第三节 PathVariable注解获取路径参数"></a>第三节 PathVariable注解获取路径参数</h3><h4 id="1-REST-风格路径参数"><a href="#1-REST-风格路径参数" class="headerlink" title="1. REST 风格路径参数"></a>1. REST 风格路径参数</h4><p>请看下面链接：</p>
<blockquote>
<p>/emp/20</p>
<p>/shop/product/iphone</p>
</blockquote>
<p>如果我们想要获取链接地址中的某个部分的值，就可以使用 @PathVariable 注解，例如上面地址中的20、iphone部分。</p>
<h4 id="2-具体操作"><a href="#2-具体操作" class="headerlink" title="2. 具体操作"></a>2. 具体操作</h4><h5 id="2-1-单个路径参数"><a href="#2-1-单个路径参数" class="headerlink" title="2.1 单个路径参数"></a>2.1 单个路径参数</h5><h6 id="2-1-1-发送请求携带参数"><a href="#2-1-1-发送请求携带参数" class="headerlink" title="2.1.1 发送请求携带参数"></a>2.1.1 发送请求携带参数</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/rest/movie/2&#125;&quot;</span>&gt;</span>携带参数movieId<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="2-1-2-handler方法获取路径参数"><a href="#2-1-2-handler方法获取路径参数" class="headerlink" title="2.1.2 handler方法获取路径参数"></a>2.1.2 handler方法获取路径参数</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//注意:&#123;movieId是一个占位符&#125;，表示获取该位置的值，@PathVariable(&quot;movieId&quot;)表示获取占位符为&quot;movieId&quot;的值</span><br><span class="hljs-meta">@GetMapping(&quot;/movie/&#123;movieId&#125;&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">findMovieById</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;movieId&quot;)</span> Integer movieId)</span></span>&#123;<br>    logger.debug(<span class="hljs-string">&quot;GET请求....&quot;</span>+movieId);<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;target&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="2-2-多个路径参数"><a href="#2-2-多个路径参数" class="headerlink" title="2.2 多个路径参数"></a>2.2 多个路径参数</h5><h6 id="2-2-1-发送请求携带参数"><a href="#2-2-1-发送请求携带参数" class="headerlink" title="2.2.1 发送请求携带参数"></a>2.2.1 发送请求携带参数</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/rest/movie/2/22/123&#125;&quot;</span>&gt;</span>携带多个参数<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="2-2-2-handler方法获取路径参数"><a href="#2-2-2-handler方法获取路径参数" class="headerlink" title="2.2.2 handler方法获取路径参数"></a>2.2.2 handler方法获取路径参数</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@GetMapping(&quot;/movie/&#123;categoryId&#125;/&#123;groupId&#125;/&#123;movieId&#125;&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">findMovieById</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;categoryId&quot;)</span> Integer categoryId,<span class="hljs-meta">@PathVariable(&quot;groupId&quot;)</span>Integer groupId,<span class="hljs-meta">@PathVariable(&quot;movieId&quot;)</span> Integer movieId)</span></span>&#123;<br>    logger.debug(<span class="hljs-string">&quot;GET请求....&quot;</span>+categoryId+<span class="hljs-string">&quot;:&quot;</span>+groupId+<span class="hljs-string">&quot;:&quot;</span>+movieId);<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;target&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="第四节-RESTFul综合案例"><a href="#第四节-RESTFul综合案例" class="headerlink" title="第四节 RESTFul综合案例"></a>第四节 RESTFul综合案例</h3><h4 id="1-案例准备"><a href="#1-案例准备" class="headerlink" title="1. 案例准备"></a>1. 案例准备</h4><p>将前面的传统CRUD案例复制并且重新导入</p>
<h4 id="2-功能清单"><a href="#2-功能清单" class="headerlink" title="2. 功能清单"></a>2. 功能清单</h4><table>
<thead>
<tr>
<th>功能</th>
<th>URL 地址</th>
<th>请求方式</th>
</tr>
</thead>
<tbody><tr>
<td>访问首页</td>
<td>/</td>
<td>GET</td>
</tr>
<tr>
<td>查询全部数据</td>
<td>/movie</td>
<td>GET</td>
</tr>
<tr>
<td>删除</td>
<td>/movie/2</td>
<td>DELETE</td>
</tr>
<tr>
<td>跳转到添加数据的表单</td>
<td>/movie/add.html</td>
<td>GET</td>
</tr>
<tr>
<td>执行保存</td>
<td>/movie</td>
<td>POST</td>
</tr>
<tr>
<td>跳转到更新数据的表单</td>
<td>/movie/2</td>
<td>GET</td>
</tr>
<tr>
<td>执行更新</td>
<td>/movie</td>
<td>PUT</td>
</tr>
</tbody></table>
<h4 id="3-访问首页"><a href="#3-访问首页" class="headerlink" title="3. 访问首页"></a>3. 访问首页</h4><h5 id="3-1-配置view-controller"><a href="#3-1-配置view-controller" class="headerlink" title="3.1 配置view-controller"></a>3.1 配置view-controller</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">mvc:view-controller</span> <span class="hljs-attr">path</span>=<span class="hljs-string">&quot;/&quot;</span> <span class="hljs-attr">view-name</span>=<span class="hljs-string">&quot;portal&quot;</span>/&gt;</span><br></code></pre></td></tr></table></figure>

<p>其它不用做任何修改</p>
<h4 id="4-查询全部"><a href="#4-查询全部" class="headerlink" title="4. 查询全部"></a>4. 查询全部</h4><h5 id="4-1-案例流程"><a href="#4-1-案例流程" class="headerlink" title="4.1 案例流程"></a>4.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_002.png" srcset="/img/loading.gif" lazyload></p>
<h5 id="4-2-具体实现"><a href="#4-2-具体实现" class="headerlink" title="4.2 具体实现"></a>4.2 具体实现</h5><h6 id="4-2-1-handler方法"><a href="#4-2-1-handler方法" class="headerlink" title="4.2.1 handler方法"></a>4.2.1 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//因为类上的RequestMapping注解的值已经是&quot;/movie&quot;了</span><br><span class="hljs-meta">@GetMapping</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">showList</span><span class="hljs-params">(Model model)</span></span>&#123;<br>    <span class="hljs-comment">//1. 调用业务层的方法查询所有的movie</span><br>    List&lt;Movie&gt; movieList = movieService.getAll();<br>    <span class="hljs-comment">//2. 将查询到的所有movie存储到请求域</span><br>    model.addAttribute(<span class="hljs-string">&quot;movieList&quot;</span>,movieList);<br>    <span class="hljs-comment">//3. 解析Thymeleaf模板显示所有movie</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;list&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="4-2-2-portal-html页面a标签的路径"><a href="#4-2-2-portal-html页面a标签的路径" class="headerlink" title="4.2.2 portal.html页面a标签的路径"></a>4.2.2 portal.html页面a标签的路径</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/movie&#125;&quot;</span>&gt;</span>显示电影列表<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="4-2-3-list页面展示-不用修改"><a href="#4-2-3-list页面展示-不用修改" class="headerlink" title="4.2.3 list页面展示(不用修改)"></a>4.2.3 list页面展示(不用修改)</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span> <span class="hljs-attr">xmlns:th</span>=<span class="hljs-string">&quot;http://www.thymeleaf.org&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>电影列表页面<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/css&quot;</span>&gt;</span><span class="css"></span><br><span class="css">            <span class="hljs-selector-tag">table</span> &#123;</span><br><span class="css">                <span class="hljs-attribute">border-collapse</span>: collapse;</span><br><span class="css">                <span class="hljs-attribute">margin</span>: <span class="hljs-number">0px</span> auto <span class="hljs-number">0px</span> auto;</span><br><span class="css">            &#125;</span><br><span class="css">            <span class="hljs-selector-tag">table</span> <span class="hljs-selector-tag">th</span>,<span class="hljs-selector-tag">td</span> &#123;</span><br><span class="css">                <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid black;</span><br><span class="css">                <span class="hljs-attribute">text-align</span>: center;</span><br><span class="css">            &#125;</span><br><span class="css">        </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>电影ID<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>电影名称<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>电影票价格<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>更新<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span> <span class="hljs-attr">th:if</span>=<span class="hljs-string">&quot;$&#123;#lists.isEmpty(movieList)&#125;&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">colspan</span>=<span class="hljs-string">&quot;5&quot;</span>&gt;</span>抱歉！没有查询到数据！<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span> <span class="hljs-attr">th:unless</span>=<span class="hljs-string">&quot;$&#123;#lists.isEmpty(movieList)&#125;&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span> <span class="hljs-attr">th:each</span>=<span class="hljs-string">&quot;movie : $&#123;movieList&#125;&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;movie.movieId&#125;&quot;</span>&gt;</span>电影ID<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;movie.movieName&#125;&quot;</span>&gt;</span>电影名称<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;movie.moviePrice&#125;&quot;</span>&gt;</span>电影票价格<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><br>                        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/movie/removeMovie(movieId=$&#123;movie.movieId&#125;)&#125;&quot;</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/movie/toUpdatePage(movieId=$&#123;movie.movieId&#125;)&#125;&quot;</span>&gt;</span>更新<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">tfoot</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">colspan</span>=<span class="hljs-string">&quot;5&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/add.html&#125;&quot;</span>&gt;</span>添加<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">tfoot</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h4 id="5-删除一行数据"><a href="#5-删除一行数据" class="headerlink" title="5. 删除一行数据"></a>5. 删除一行数据</h4><h5 id="5-1-案例流程"><a href="#5-1-案例流程" class="headerlink" title="5.1 案例流程"></a>5.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_003.png" srcset="/img/loading.gif" lazyload></p>
<p>重点在于将 GET 请求转换为 DELETE。基本思路是：通过一个<strong>通用表单</strong>，使用 <strong>Vue</strong> 代码先把 GET 请求转换为 POST，然后再借助 <strong>hiddenHttpMethodFilter</strong> 在服务器端把 POST 请求转为 DELETE。 </p>
<h5 id="5-2-具体实现"><a href="#5-2-具体实现" class="headerlink" title="5.2 具体实现"></a>5.2 具体实现</h5><h6 id="5-2-1-创建通用表单"><a href="#5-2-1-创建通用表单" class="headerlink" title="5.2.1 创建通用表单"></a>5.2.1 创建通用表单</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-comment">&lt;!-- 组件名称：通用表单 --&gt;</span><br><span class="hljs-comment">&lt;!-- 组件作用：把删除超链接的 GET 请求转换为 POST，并携带 _method 请求参数 --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;convertForm&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br>    <br>    <span class="hljs-comment">&lt;!-- 请求参数作用：告诉服务器端 hiddenHttpMethodFilter 要转换的目标请求方式 --&gt;</span><br>    <span class="hljs-comment">&lt;!-- 请求参数名：_method，这是 hiddenHttpMethodFilter 中规定的 --&gt;</span><br>    <span class="hljs-comment">&lt;!-- 请求参数值：delete，这是因为我们希望服务器端将请求方式最终转换为 delete --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;_method&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;delete&quot;</span>/&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="5-2-2-删除超链接绑定单击响应函数"><a href="#5-2-2-删除超链接绑定单击响应函数" class="headerlink" title="5.2.2 删除超链接绑定单击响应函数"></a>5.2.2 删除超链接绑定单击响应函数</h6><ol>
<li>引入vue</li>
</ol>
<p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_004.png" srcset="/img/loading.gif" lazyload></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/script/vue.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ol start="2">
<li> 删除超链接绑定单击事件</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/movie/&#125;+$&#123;movie.movieId&#125;&quot;</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;deleteMovie()&quot;</span>&gt;</span>删除<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ol start="3">
<li>vue代码</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">var</span> vue = <span class="hljs-keyword">new</span> Vue(&#123;<br>    <span class="hljs-string">&quot;el&quot;</span>:<span class="hljs-string">&quot;#app&quot;</span>,<br>    <span class="hljs-string">&quot;methods&quot;</span>:&#123;<br>        <span class="hljs-function"><span class="hljs-title">deleteMovie</span>(<span class="hljs-params"></span>)</span>&#123;<br>            <span class="hljs-comment">//1. 阻止默认事件</span><br>            event.preventDefault()<br>            <span class="hljs-comment">//2. 创建一个空表单:设置表单的action的值和当前a标签的路径一致</span><br>            <span class="hljs-keyword">var</span> deleteForm = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&quot;deleteForm&quot;</span>);<br>            deleteForm.action = event.target.href<br>            <span class="hljs-comment">//3. 提交表单</span><br>            deleteForm.submit()<br>        &#125;<br>    &#125;<br>&#125;);<br></code></pre></td></tr></table></figure>

<h6 id="5-2-3-handler方法"><a href="#5-2-3-handler方法" class="headerlink" title="5.2.3 handler方法"></a>5.2.3 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@DeleteMapping(&quot;/&#123;movieId&#125;&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">removeMovie</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;movieId&quot;)</span> String movieId)</span></span>&#123;<br>    <span class="hljs-comment">//调用业务层的方法根据id删除movie</span><br>    movieService.removeMovieById(movieId);<br>    <span class="hljs-comment">//重新查询所有</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;redirect:/movie&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="6-跳转到添加数据的表单-不用修改"><a href="#6-跳转到添加数据的表单-不用修改" class="headerlink" title="6. 跳转到添加数据的表单(不用修改)"></a>6. 跳转到添加数据的表单(不用修改)</h4><h5 id="6-1-案例流程"><a href="#6-1-案例流程" class="headerlink" title="6.1 案例流程"></a>6.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_005.png" srcset="/img/loading.gif" lazyload></p>
<h5 id="6-2-具体实现"><a href="#6-2-具体实现" class="headerlink" title="6.2 具体实现"></a>6.2 具体实现</h5><h6 id="6-2-1-配置view-controller"><a href="#6-2-1-配置view-controller" class="headerlink" title="6.2.1 配置view-controller"></a>6.2.1 配置view-controller</h6><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!--8. 使用view-controller访问添加页面--&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">mvc:view-controller</span> <span class="hljs-attr">path</span>=<span class="hljs-string">&quot;/add.html&quot;</span> <span class="hljs-attr">view-name</span>=<span class="hljs-string">&quot;add&quot;</span>/&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="6-2-2-创建页面"><a href="#6-2-2-创建页面" class="headerlink" title="6.2.2 创建页面"></a>6.2.2 创建页面</h6><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_006.png" srcset="/img/loading.gif" lazyload></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">th:action</span>=<span class="hljs-string">&quot;@&#123;/movie&#125;&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br>    <br>    电影名称：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;movieName&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br>    电影票价格：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;moviePrice&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br>    <br>    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>保存<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br>    <br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h4 id="7-执行添加"><a href="#7-执行添加" class="headerlink" title="7. 执行添加"></a>7. 执行添加</h4><h5 id="7-1-案例流程"><a href="#7-1-案例流程" class="headerlink" title="7.1 案例流程"></a>7.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_007.png" srcset="/img/loading.gif" lazyload></p>
<h5 id="7-2-具体实现"><a href="#7-2-具体实现" class="headerlink" title="7.2 具体实现"></a>7.2 具体实现</h5><h6 id="7-2-1-handler方法"><a href="#7-2-1-handler方法" class="headerlink" title="7.2.1 handler方法"></a>7.2.1 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PostMapping</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">addMovie</span><span class="hljs-params">(Movie movie)</span></span>&#123;<br>    <span class="hljs-comment">//调用业务层的方法添加Movie</span><br>    movieService.saveMovie(movie);<br>    <span class="hljs-comment">//重新查询所有</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;redirect:/movie&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="7-2-2-添加页面"><a href="#7-2-2-添加页面" class="headerlink" title="7.2.2 添加页面"></a>7.2.2 添加页面</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span> <span class="hljs-attr">xmlns:th</span>=<span class="hljs-string">&quot;http://www.thymeleaf.org&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>添加电影页面<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">th:action</span>=<span class="hljs-string">&quot;@&#123;/movie&#125;&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br><br>        电影名称：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;movieName&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br>        电影票价格：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;moviePrice&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>保存<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br></code></pre></td></tr></table></figure>



<h4 id="8-跳转到更新数据页面"><a href="#8-跳转到更新数据页面" class="headerlink" title="8. 跳转到更新数据页面"></a>8. 跳转到更新数据页面</h4><h5 id="8-1-案例流程"><a href="#8-1-案例流程" class="headerlink" title="8.1 案例流程"></a>8.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_008.png" srcset="/img/loading.gif" lazyload></p>
<h5 id="8-2-具体实现"><a href="#8-2-具体实现" class="headerlink" title="8.2 具体实现"></a>8.2 具体实现</h5><h6 id="8-2-1-handler方法"><a href="#8-2-1-handler方法" class="headerlink" title="8.2.1 handler方法"></a>8.2.1 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@GetMapping(&quot;/&#123;movieId&#125;&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">toUpdatePage</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;movieId&quot;)</span> String movieId,Model model)</span></span>&#123;<br>    <span class="hljs-comment">//1. 根据要修改的电影的id查询到当前电影的信息</span><br>    Movie movie = movieService.getMovieById(movieId);<br>    <span class="hljs-comment">//2. 将当前电影的信息存储到请求域</span><br>    model.addAttribute(<span class="hljs-string">&quot;movie&quot;</span>,movie);<br>    <span class="hljs-comment">//3. 解析update页面</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;update&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="8-2-2-修改更新的超链接"><a href="#8-2-2-修改更新的超链接" class="headerlink" title="8.2.2 修改更新的超链接"></a>8.2.2 修改更新的超链接</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@&#123;/movie/&#125;+$&#123;movie.movieId&#125;&quot;</span>&gt;</span>更新<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h6 id="8-2-3-页面回显数据"><a href="#8-2-3-页面回显数据" class="headerlink" title="8.2.3 页面回显数据"></a>8.2.3 页面回显数据</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">th:action</span>=<span class="hljs-string">&quot;@&#123;/movie&#125;&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br>    <span class="hljs-comment">&lt;!--映射成put请求--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;_method&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;put&quot;</span>/&gt;</span><br>    <span class="hljs-comment">&lt;!--使用隐藏域绑定movieId--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;movieId&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;movie.movieId&#125;&quot;</span> /&gt;</span><br>    电影名称：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;movieName&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;movie.movieName&#125;&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br>    电影票价格：<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;moviePrice&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;movie.moviePrice&#125;&quot;</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>更新<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h4 id="9-执行更新"><a href="#9-执行更新" class="headerlink" title="9. 执行更新"></a>9. 执行更新</h4><h5 id="9-1-案例流程"><a href="#9-1-案例流程" class="headerlink" title="9.1 案例流程"></a>9.1 案例流程</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_009.png" srcset="/img/loading.gif" lazyload></p>
<h5 id="9-2-具体实现"><a href="#9-2-具体实现" class="headerlink" title="9.2 具体实现"></a>9.2 具体实现</h5><h6 id="9-2-1-handler方法"><a href="#9-2-1-handler方法" class="headerlink" title="9.2.1 handler方法"></a>9.2.1 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PutMapping</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">updateMovie</span><span class="hljs-params">(Movie movie)</span></span>&#123;<br>    <span class="hljs-comment">//1. 调用业务层的方法修改电影信息</span><br>    movieService.updateMovie(movie);<br>    <span class="hljs-comment">//2. 重新查询所有</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;redirect:/movie&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="第五节-REST的小结"><a href="#第五节-REST的小结" class="headerlink" title="第五节 REST的小结"></a>第五节 REST的小结</h3><ol>
<li>解决什么问题: 从根据功能设计url变成根据资源设计url</li>
<li>是什么:资源状态转移<strong>Re</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer</li>
<li>特征:<ol>
<li>一个url就代表一个资源，也就是说通过url我们可以知道当前请求操作的是什么资源</li>
<li>请求方式代表操作,也就是说通过请求方式我们知道当前请求对当前资源做的是何种操作</li>
</ol>
</li>
<li>效果:<ol>
<li>url更加简洁</li>
<li>url更加隐晦</li>
<li>操作的幂等性</li>
</ol>
</li>
<li>怎么实现:<ol>
<li>请求方式映射:HTML默认只能发送GET和POST请求，SpringMVC在某些时候需要将POST请求映射成PUT或者DELETE请求</li>
<li>GetMapping、PostMapping、DeleteMapping、PutMapping要选择情况使用</li>
<li>合理设计url</li>
<li>使用Pathvariable注解获取REST风格的url上的路径参数</li>
</ol>
</li>
</ol>
<h2 id="第二章-Ajax交互"><a href="#第二章-Ajax交互" class="headerlink" title="第二章 Ajax交互"></a>第二章 Ajax交互</h2><h3 id="第一节-获取请求参数"><a href="#第一节-获取请求参数" class="headerlink" title="第一节 获取请求参数"></a>第一节 获取请求参数</h3><h4 id="1-获取普通类型参数-与之前获取请求参数的方式一致"><a href="#1-获取普通类型参数-与之前获取请求参数的方式一致" class="headerlink" title="1. 获取普通类型参数(与之前获取请求参数的方式一致)"></a>1. 获取普通类型参数(与之前获取请求参数的方式一致)</h4><h5 id="1-1-引入JavaScript库"><a href="#1-1-引入JavaScript库" class="headerlink" title="1.1 引入JavaScript库"></a>1.1 引入JavaScript库</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_010.png" srcset="/img/loading.gif" lazyload></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;script/vue.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;script/axios.min.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h5 id="1-2-前端代码"><a href="#1-2-前端代码" class="headerlink" title="1.2 前端代码"></a>1.2 前端代码</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-function"><span class="hljs-title">sendCommon</span>(<span class="hljs-params"></span>)</span>&#123;<br>    axios(&#123;<br>        <span class="hljs-string">&quot;method&quot;</span>:<span class="hljs-string">&quot;POST&quot;</span>,<br>        <span class="hljs-string">&quot;url&quot;</span>:<span class="hljs-string">&quot;ajax/commonParameter&quot;</span>,<br>        <span class="hljs-comment">//params表示携带普通类型的参数</span><br>        <span class="hljs-string">&quot;params&quot;</span>:&#123;<br>            <span class="hljs-string">&quot;userName&quot;</span>:<span class="hljs-string">&quot;tom&quot;</span>,<br>            <span class="hljs-string">&quot;password&quot;</span>:<span class="hljs-string">&quot;123456&quot;</span><br>        &#125;<br>    &#125;).then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> &#123;<br><br>    &#125;)<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="1-3-后端代码"><a href="#1-3-后端代码" class="headerlink" title="1.3 后端代码"></a>1.3 后端代码</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping(&quot;/commonParameter&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">commonParameter</span><span class="hljs-params">(User user)</span></span>&#123;<br>    <span class="hljs-comment">//获取异步请求携带的普通类型参数，和以前获取同步请求携带的参数是一样的</span><br>    logger.debug(user.toString());<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;hello&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="2-获取JSON请求体参数"><a href="#2-获取JSON请求体参数" class="headerlink" title="2. 获取JSON请求体参数"></a>2. 获取JSON请求体参数</h4><h5 id="2-1-前端代码"><a href="#2-1-前端代码" class="headerlink" title="2.1 前端代码"></a>2.1 前端代码</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-function"><span class="hljs-title">sendJsonBody</span>(<span class="hljs-params"></span>)</span>&#123;<br>    axios(&#123;<br>        <span class="hljs-string">&quot;method&quot;</span>:<span class="hljs-string">&quot;POST&quot;</span>,<br>        <span class="hljs-string">&quot;url&quot;</span>:<span class="hljs-string">&quot;ajax/jsonBodyParameter&quot;</span>,<br>        <span class="hljs-comment">//data表示携带json请求体类型的参数</span><br>        <span class="hljs-string">&quot;data&quot;</span>:&#123;<br>            <span class="hljs-string">&quot;userName&quot;</span>:<span class="hljs-string">&quot;tom&quot;</span>,<br>            <span class="hljs-string">&quot;password&quot;</span>:<span class="hljs-string">&quot;123456&quot;</span><br>        &#125;<br>    &#125;).then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> &#123;<br><br>    &#125;)<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="2-2-后端代码"><a href="#2-2-后端代码" class="headerlink" title="2.2 后端代码"></a>2.2 后端代码</h5><h6 id="2-2-1-引入jackson依赖"><a href="#2-2-1-引入jackson依赖" class="headerlink" title="2.2.1 引入jackson依赖"></a>2.2.1 引入jackson依赖</h6><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.fasterxml.jackson.core<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jackson-databind<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.12.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>如果忘记导入这个依赖，会看到下面的错误页面 </p>
<p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_011.png" srcset="/img/loading.gif" lazyload></p>
<p>关于 SpringMVC 和 Jackson jar包之间的关系，需要注意：当 SpringMVC 需要解析 JSON 数据时就需要使用 Jackson 的支持。但是 SpringMVC 的 jar 包并没有依赖 Jackson，所以需要我们自己导入。</p>
<p>我们自己导入时需要注意：SpringMVC 和 Jackson 配合使用有版本的要求。二者中任何一个版本太高或太低都不行。</p>
<p>SpringMVC 解析 JSON 数据包括两个方向：</p>
<ul>
<li>从 JSON 字符串到 Java 实体类。</li>
<li>从 Java 实体类到 JSON 字符串。</li>
</ul>
<p>另外，如果导入了 Jackson 依赖，但是没有开启 mvc:annotation-driven 功能，那么仍然会返回上面的错误页面。</p>
<p>也就是说，我们可以这么总结 SpringMVC 想要解析 JSON 数据需要两方面支持：</p>
<ul>
<li>mvc:annotation-driven</li>
<li>引入 Jackson 依赖</li>
</ul>
<p>还有一点，如果运行环境是 Tomcat7，那么在 Web 应用启动时会抛出下面异常：</p>
<blockquote>
<p>org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19</p>
</blockquote>
<p>解决办法是使用 Tomcat8 或更高版本。</p>
<h6 id="2-2-2-handler方法"><a href="#2-2-2-handler方法" class="headerlink" title="2.2.2 handler方法"></a>2.2.2 handler方法</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping(&quot;/jsonBodyParameter&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">jsonBodyParameter</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> User user)</span></span>&#123;<br>    <span class="hljs-comment">//1. 获取Json请求体类型的参数必须要封装到POJO对象或者是Map中</span><br>    <span class="hljs-comment">//2. POJO参数或者Map参数的前面一定要加入RequestBody注解</span><br>    <span class="hljs-comment">//3. 你的项目中一定要引入jackson的依赖(因为SpringMVC默认支持jackson)</span><br>    <span class="hljs-comment">//获取Json请求体类型的请求参数和获取普通类型的参数不一样</span><br>    logger.debug(user.toString());<br>    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="2-2-3-RequestBody注解"><a href="#2-2-3-RequestBody注解" class="headerlink" title="2.2.3 RequestBody注解"></a>2.2.3 RequestBody注解</h6><p>适用 @RequestBody 注解的场景：请求体整个是一个 JSON 数据 </p>
<p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_012.png" srcset="/img/loading.gif" lazyload></p>
<p>Request Payload 翻译成中文大致可以说：请求负载。 </p>
<h3 id="第二节-响应JSON类型数据"><a href="#第二节-响应JSON类型数据" class="headerlink" title="第二节 响应JSON类型数据"></a>第二节 响应JSON类型数据</h3><h4 id="1-前端代码"><a href="#1-前端代码" class="headerlink" title="1. 前端代码"></a>1. 前端代码</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-function"><span class="hljs-title">sendJsonBody</span>(<span class="hljs-params"></span>)</span>&#123;<br>    axios(&#123;<br>        <span class="hljs-string">&quot;method&quot;</span>:<span class="hljs-string">&quot;POST&quot;</span>,<br>        <span class="hljs-string">&quot;url&quot;</span>:<span class="hljs-string">&quot;ajax/jsonBodyParameter&quot;</span>,<br>        <span class="hljs-comment">//data表示携带json请求体类型的参数</span><br>        <span class="hljs-string">&quot;data&quot;</span>:&#123;<br>            <span class="hljs-string">&quot;userName&quot;</span>:<span class="hljs-string">&quot;tom&quot;</span>,<br>            <span class="hljs-string">&quot;password&quot;</span>:<span class="hljs-string">&quot;123456&quot;</span><br>        &#125;<br>    &#125;).then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> &#123;<br>        <span class="hljs-built_in">console</span>.log(response.data.movieName)<br>    &#125;)<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="2-后端代码"><a href="#2-后端代码" class="headerlink" title="2. 后端代码"></a>2. 后端代码</h4><p>前提是项目中引入了jackson的依赖</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@ResponseBody</span><br><span class="hljs-meta">@RequestMapping(&quot;/jsonBodyParameter&quot;)</span><br><span class="hljs-function"><span class="hljs-keyword">public</span> Movie <span class="hljs-title">jsonBodyParameter</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> User user)</span></span>&#123;<br>    logger.debug(user.toString());<br><br>    Movie movie = <span class="hljs-keyword">new</span> Movie(<span class="hljs-number">1</span>, <span class="hljs-string">&quot;西游记&quot;</span>, <span class="hljs-number">40.0</span>);<br>    <span class="hljs-comment">//目标:将movie转成json字符串响应给客户端</span><br>    <span class="hljs-comment">//1. handler方法的返回值就是你要转成json的那个对象</span><br>    <span class="hljs-comment">//2. handler方法上必须添加ResponseBody注解</span><br>    <span class="hljs-comment">//3. 你的项目中一定要引入了jackson的依赖</span><br>    <span class="hljs-keyword">return</span> movie;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="3-常见错误"><a href="#3-常见错误" class="headerlink" title="3. 常见错误"></a>3. 常见错误</h4><h5 id="3-1-500-错误"><a href="#3-1-500-错误" class="headerlink" title="3.1 500 错误"></a>3.1 500 错误</h5><p><img src="http://www.slx.blue/2021/12/11/springMVC-02/tu_014.png" srcset="/img/loading.gif" lazyload></p>
<p>出现上面的错误页面，表示SpringMVC 为了将 实体类对象转换为 JSON 数据, 需要转换器。但是现在找不到转换器。它想要成功完成转换需要两方面支持：</p>
<ul>
<li>mvc:annotation-driven</li>
<li>引入Jackson依赖</li>
</ul>
<h5 id="3-2-406-错误-了解"><a href="#3-2-406-错误-了解" class="headerlink" title="3.2 406 错误(了解)"></a>3.2 406 错误(了解)</h5><p>问题出现的原因：</p>
<ul>
<li>请求地址扩展名：html</li>
<li>服务器端打算返回的数据格式：JSON</li>
</ul>
<p>上面二者不一致。SpringMVC 要坚守一个商人的良心，不能干『挂羊头，卖狗肉』的事儿。解决办法有三种思路：</p>
<ul>
<li>第一种方法：不使用请求扩展名</li>
<li>第二种方法：使用和实际返回的数据格式一致的扩展名</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>dispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>*.html<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>*.json<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li>第三种方法：使用一个 HTTP 协议中没有被定义的扩展名，例如：*.do</li>
</ul>
<h4 id="4-RestController注解"><a href="#4-RestController注解" class="headerlink" title="4. RestController注解"></a>4. RestController注解</h4><h5 id="4-1-提取ResponseBody注解"><a href="#4-1-提取ResponseBody注解" class="headerlink" title="4.1 提取ResponseBody注解"></a>4.1 提取ResponseBody注解</h5><p>如果类中每个方法上都标记了 @ResponseBody 注解，那么这些注解就可以提取到类上。 </p>
<h5 id="4-2-合并注解"><a href="#4-2-合并注解" class="headerlink" title="4.2 合并注解"></a>4.2 合并注解</h5><p>类上的ResponseBody 注解可以和Controller 注解合并为RestController 注解。所以使用了RestController 注解就相当于给类中的每个方法都加了ResponseBody 注解。 </p>
<h5 id="4-3-RestController源码"><a href="#4-3-RestController源码" class="headerlink" title="4.3 RestController源码"></a>4.3 RestController源码</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><br><span class="hljs-meta">@Target(ElementType.TYPE)</span><br><span class="hljs-meta">@Retention(RetentionPolicy.RUNTIME)</span><br><span class="hljs-meta">@Documented</span><br><span class="hljs-meta">@Controller</span><br><span class="hljs-meta">@ResponseBody</span><br><span class="hljs-keyword">public</span> <span class="hljs-meta">@interface</span> RestController &#123;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * The value may indicate a suggestion for a logical component name,</span><br><span class="hljs-comment">     * to be turned into a Spring bean in case of an autodetected component.</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> the suggested component name, if any (or empty String otherwise)</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@since</span> 4.0.1</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@AliasFor(annotation = Controller.class)</span><br>    <span class="hljs-function">String <span class="hljs-title">value</span><span class="hljs-params">()</span> <span class="hljs-keyword">default</span> &quot;&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>


            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/springMVC/">springMVC</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/springMVC/">springMVC</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客目前大部分文章都是参考尚硅谷或者马士兵教育的学习资料！<a href="http://www.atguigu.com/" rel="nofollow noopener"官网地址！</a> 
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/12/13/java-memento/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">java-备忘录模式</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/12/10/springMVC-01/">
                        <span class="hidden-mobile">springMVC-01</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">

  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
	<!--《添加网站运行时间 -->
<br/>

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date(); 

function createtime() {
    //此处修改你的建站时间或者网站上线时间
    var grt = new Date('11/02/2021 21:39:00');
    now.setTime(now.getTime() + 250);
    days = (now - grt) / 1000 / 60 / 60 / 24;

    dnum = Math.floor(days);
    hours = (now - grt) / 1000 / 60 / 60 - (24 * dnum);
    hnum = Math.floor(hours);
    if (String(hnum).length == 1) {
        hnum = "0" + hnum;
    }
    minutes = (now - grt) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes);
    if (String(mnum).length == 1) {
        mnum = "0" + mnum;
    }
    seconds = (now - grt) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds);
    if (String(snum).length == 1) {
        snum = "0" + snum;
    }
    document.getElementById("timeDate").innerHTML = " 本站已各种夹缝中安全运行 " + dnum + " 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()", 250);
</script>

<!-- 添加网站运行时间》-->
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
